#include<iostream>
#include<pthread.h>
#include<unistd.h>
#include<stdlib.h>

using namespace std;

//线程函数
void* threadroutine(void * arg)
{
    const char* name=(const char*)arg;
    int cnt=5;
    while(true)
    {
        cout<<name<<",pid: "<<getpid()<<endl;
        sleep(1);
        cnt--;
        if(cnt==0) break;
    }
    return (void*)1;//我的当前平台，地址是64位，8字节，而int是4字节，不进行强转会导致混乱
}

int main()
{
    pthread_t tid;
    //创建线程
    pthread_create(&tid,nullptr,threadroutine,(void*)"new thread");

    void * retval;
    pthread_join(tid,&retval);// main thread等待的时候，默认是阻塞等待的！

    cout << "main thread quit ..., ret: " << (long long int)retval << endl;
    

    // while(true)
    // {
    //     cout<<"main thread,pid: "<<getpid()<<endl;
    //     sleep(1);
    // }
    return 0;
}

